﻿#region Using Directives

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;

    using Csla;
   
#endregion

namespace MarketPulse.BusinessLogic.Core
{
    /// <summary>
    /// Base business class that all read only business objects i.e. those that would inherit
    /// directly from ReadOnlyBusinessBase, should inherit from.
    /// </summary>
    /// <typeparam name="T">Must be derive from MarketPulseBase (this class)</typeparam>
    [Serializable]
    public abstract class MarketPulseReadOnlyBase<T> : ReadOnlyBase<T> where T : MarketPulseReadOnlyBase<T>
    {
        #region Constructors

            /// <summary>
            /// Constructs a MarketPulseReadOnlyBase
            /// </summary>
            protected MarketPulseReadOnlyBase()
            {
            }

        #endregion

        #region Methods

            /// <summary>
            /// (Overriden) Method used to return a string representation of this BusinessObject made up of the object type and it's uniquely idetifiying Guid
            /// </summary>
            /// <returns>A string representation of the BusinessObject</returns>
            public override string ToString()
            {
                StringBuilder objectString = new StringBuilder();
                objectString.Append(typeof(T).ToString());
                objectString.Append(" GUID: [ " + GUID + " ] ");
                return objectString.ToString();
            }

        #endregion

        #region Properties

            /// <summary>
            /// This is the unique identifier used to identify all business objects within the system
            /// </summary>
            public static PropertyInfo<Nullable<Guid>> GUIDProperty = RegisterProperty<Nullable<Guid>>(p => p.GUID);
            /// <summary>
            /// This is the unique identifier used to identify all business objects within the system
            /// </summary>
            [DataObjectField(true, true)]
            public Nullable<Guid> GUID
            {
                get { return GetProperty(GUIDProperty); }
            }

            /// <summary>
            /// Boolean used to mark the object as deleted or unused (obsolete)
            /// </summary>
            public static PropertyInfo<bool> ObsoleteProperty = RegisterProperty<bool>(p => p.Obsolete);
            /// <summary>
            /// Boolean used to mark the object as deleted or unused (obsolete)
            /// </summary>
            public bool Obsolete
            {
                get { return GetProperty(ObsoleteProperty); }
            }

            /// <summary>
            /// The ID of the user who initially created the object.
            /// </summary>
            public static PropertyInfo<Guid> InsertUserGUIDProperty = RegisterProperty<Guid>(p => p.InsertUserGUID);
            /// <summary>
            /// The ID of the user who initially created the object.
            /// </summary>
            public Guid InsertUserGUID
            {
                get { return GetProperty(InsertUserGUIDProperty); }
            }

            /// <summary>
            /// The time and date of when the object was first created
            /// </summary>
            public static PropertyInfo<SmartDate> InsertDateTimeProperty = RegisterProperty<SmartDate>(p => p.InsertDateTime);
            /// <summary>
            /// The time and date of when the object was first created
            /// </summary>
            public string InsertDateTime
            {
                get { return GetPropertyConvert<SmartDate, string>(InsertDateTimeProperty); }
            }

            /// <summary>
            /// The ID of the user who last caused the object to be updated.
            /// </summary>
            public static PropertyInfo<Guid> UpdateUserGUIDProperty = RegisterProperty<Guid>(p => p.UpdateUserGUID);
            /// <summary>
            /// The ID of the user who last caused the object to be updated.
            /// </summary>
            public Guid UpdateUserGUID
            {
                get { return GetProperty(UpdateUserGUIDProperty); }
            }

            /// <summary>
            /// The time and date of when the object was last updated
            /// </summary>
            public static PropertyInfo<SmartDate> UpdateDateTimeProperty = RegisterProperty<SmartDate>(p => p.UpdateDateTime);
            /// <summary>
            /// The time and date of when the object was last updated
            /// </summary>
            public string UpdateDateTime
            {
                get { return GetPropertyConvert<SmartDate, string>(UpdateDateTimeProperty); }
            }

        #endregion
    }
}
